package com.lx.algorithm.code;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-12-30 15:00:57
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-12-30     张李鑫                     1.0         1.0 Version
 */
public class Code06 {
    /**
     * 给定一个正整数M，请构造出一个长度为M的数组arr，要求
     * 对任意的i、j、k三个位置，如果i<j<k，都有arr[i] + arr[k] != 2*arr[j]
     * 返回构造出的arr
     * <p>
     * ps:人为构造左边为基数右边为偶数的数组
     */
    public static int[] makeNumber(int m) {
        if (m == 1) {
            return new int[]{1};
        }
        int[] base = makeNumber((m + 1) / 2);
        int[] ans = new int[m];
        int index = 0;
        while (index < (m + 1) / 2) {
            ans[index] = base[index] * 2 - 1;
            index++;
        }
        for (int i = 0; index < m; index++, i++) {
            ans[index] = base[i] * 2;
        }
        return ans;
    }
}
